<template>
  <div class="home">
    <div class="baberrage-wrapper">
      <vue-baberrage
        :isShow="barrageIsShow"
        :barrageList="barrageList"
        :throttleGap="throttleGap"
        :maxWordCount="maxWordCount"
        :loop="barrageLoop"
      >
        <template v-slot:default="slotProps">
          <div class="berrage-box">
            {{ slotProps.item.msg }}
          </div>
        </template>
      </vue-baberrage>
    </div>

    <img class="btn-share" src="~@/assets/img/home/btn_share.png" alt="分享" />
    <img
      class="btn-start"
      src="~@/assets/img/home/btn_start.png"
      alt="开始答题"
      @click="start"
    />
    <p class="tips">奖品数量有限，发完即止哦~</p>

    <div class="nav">
      <div>
        <img
          src="~@/assets/img/home/img_hjjl.png"
          alt="获奖记录"
          @click="goToUrl('getRecord')"
        />
      </div>
      <div>
        <img
          src="~@/assets/img/home/img_shxx.png"
          alt="收货地址"
          @click="goToUrl('takeAddress')"
        />
      </div>
      <div>
        <img
          src="~@/assets/img/home/img_yjdm.png"
          alt=""
          @click="goToUrl('sendRecord')"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { WxShare } from "@/utils/wxConfig";
import { getAllMessage } from "@/api/common";

export default {
  name: "Home",
  data() {
    return {
      barrageIsShow: true, //是否展示弹幕
      barrageLoop: true, //是否循环播放
      maxWordCount: 3,
      throttleGap: 5000, //消息间隔
      barrageList: [], //弹幕列表，格式为数组
    };
  },
  methods: {
    async getAllMessage() {
      const openid = localStorage.getItem("openid");
      if (!openid) return;
      this.$showLoading();
      try {
        const res = await getAllMessage();
        const data = res.data;
        if (data.errorCode === 0) {
          const rows = data.data;
          this.barrageList = rows;
        } else {
          this.barrageList = [];
        }
      } catch (e) {
        console.log(e);
        this.barrageList = [];
      }
      this.$closeLoading();
    },
    start() {
      this.$parent.startPlay();
      this.$router.push("/subject1");
    },
    handleShare() {
      WxShare();
    },
    goToUrl(url) {
      this.$router.push(url);
    },
  },
  created() {
    this.handleShare();
  },
  mounted() {
    this.getAllMessage();
  },
};
</script>

<style lang="scss" scoped>
.home {
  width: 100%;
  height: 100%;
  min-height: 100vh;
  overflow: hidden;
  background-image: url("http://qiniu.whxgjt.com/dfh2/bg_start.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  box-sizing: border-box;
  position: relative;

  .btn-share {
    width: 55px;
    height: 56px;
    position: absolute;
    top: 13px;
    right: 10px;
  }

  .btn-start {
    width: 265px;
    height: 69.5px;
    position: absolute;
    bottom: 94.5px;
    left: 47.5px;
  }

  .tips {
    width: 100%;
    font-size: 12px;
    font-family: SourceHanSansCN;
    font-weight: 500;
    text-align: center;
    // line-height: 25px;
    color: rgba(255, 191, 120, 0.5);
    position: absolute;
    bottom: 75px;
  }

  .baberrage-wrapper {
    width: 100%;
    height: 400px;
    overflow: hidden;
    position: relative;
    z-index: 9;
  }

  /deep/ .berrage-box {
    display: inline-block;
    height: 35px;
    padding: 0 20px;
    line-height: 35px;
    font-size: 15px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #5e0c0e;
    background: rgba(255, 255, 255, 0.8);
    border: 2px solid rgba(94, 12, 14, 0.8);
    border-radius: 19px;
  }

  .nav {
    width: 100%;
    padding: 0 30px;
    position: absolute;
    bottom: 46px;
    box-sizing: border-box;
    display: flex;
    div {
      flex: 1;
      text-align: center;
      border-right: 1px solid rgba(255, 215, 138, 1);
      display: flex;
      justify-content: center;
      align-items: center;
      img {
        width: 76px;
        height: 14px;
      }
      &:last-child {
        border-right: 0;
        img {
          width: 90px;
          height: 25px;
        }
      }
    }
  }
}

@media only screen and (max-height: 700px) {
  .btn-start {
    bottom: 60px !important;
  }
  .tips {
    bottom: 40px !important;
  }
  .nav {
    bottom: 20px !important;
  }
}
</style>